<?php


namespace app\index\controller;


use app\common\model\TestModel;
use think\Db;

class Inset
{
    private $testModel; // 测试表

    public function __construct()
    {
        $this->testModel = new TestModel();
    }

    public function index(){
        // 单条插入数据
//        $inSetData = [
//          'name' => '夏历',
//          'age' => 19,
//          'create_time' => time(),
//        ];
//        $Info = $this->testModel->save($inSetData);

        $inSetData = [];
        for ($i = 0; $i < 1000; $i++){
            $inSetData[$i] = ['name' => '夏历'.$i, 'age' => 195,'create_time' => time()];
        }
//        $Info =  Db::execute('TRUNCATE TABLE test');
        // 批量插入数据
        $Info = $this->testModel->strict(false)->limit(100)->insertAll($inSetData);

        if($Info < 0){
            return json(['status' => 'success', 'message' => '添加失败'])->code(500);
        }
        return json(['status' => 'success', 'message' => '操作成功', 'data' => '新增'.$Info.'条数据成功'])->code(200);

    }

    // 更新临时时间

}